package online.szlib.com.core.services;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import online.szlib.com.core.domain.Comment;
import online.szlib.com.core.repositories.CommentRepository;

@Service("commentService")
public class CommentServiceImpl implements CommentService {

	@Autowired
	private CommentRepository commentRepository;
	
	public List<Comment> listComments(){
		return commentRepository.findAll();
	}
	
	public void deleteComment(Comment comment){
		commentRepository.delete(comment);
	}
	
	public Long create(Comment comment){
		commentRepository.saveAndFlush(comment);
		return comment.getCommentId();
	}
	
	public void update(Comment comment){
		commentRepository.saveAndFlush(comment);
	}
	
	public Comment getComment(long commentid){
		return commentRepository.findOne(commentid);
	}
	
	public void deleteById(Long id){
		commentRepository.delete(id);
	}
	
}
